<template>
  <el-dialog
    title="学员详情"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="110px">
    <el-form-item label="学员姓名" prop="studentName">
      {{dataForm.studentName}}
    </el-form-item>
    <el-form-item label="学员阶段" prop="studentStage">
      {{dataForm.studentStage}}
    </el-form-item>
    <el-form-item label="课程顾问" prop="consultant">
      {{dataForm.consultant}}
    </el-form-item>
    <el-form-item label="试听意向度" prop="listeningIntentionality">
      {{dataForm.listeningIntentionality}}
    </el-form-item>
    <el-form-item label="来源渠道" prop="sourceChannel">
      {{dataForm.sourceChannel}}
    </el-form-item>
    <el-form-item label="跟进状态	" prop="followStatus">
      {{dataForm.followStatus}}
    </el-form-item>
    <el-form-item label="上次跟进时间" prop="followTime">
      {{dataForm.followTime}}
    </el-form-item>
    <el-form-item label="课堂状态" prop="classroomStatus">
      {{dataForm.classroomStatus}}
    </el-form-item>
    <el-form-item label="考勤状态" prop="attendanceStatus">
      {{dataForm.attendanceStatus}}
    </el-form-item>
    <el-form-item label="是否退订" prop="isUnsubscribe">
      {{dataForm.isUnsubscribe}}
    </el-form-item>
    <el-form-item label="试听时间" prop="auditionTime">
      {{dataForm.auditionTime}}
    </el-form-item>
    <el-form-item label="预约人" prop="appointmentPerson">
      {{dataForm.appointmentPerson}}
    </el-form-item>
    <el-form-item label="预约时间" prop="appointmentTime">
      {{dataForm.appointmentTime}}
    </el-form-item>
    <el-form-item label="报名意向度" prop="registrationIntention">
      {{dataForm.registrationIntention}}
    </el-form-item>
    <el-form-item label="学员类型" prop="studentType">
      {{dataForm.studentType}}
    </el-form-item>
    <el-form-item label="学员状态" prop="studentStatus">
      {{dataForm.studentStatus}}
    </el-form-item>
    <el-form-item label="辅导老师" prop="coachTeacher">
      {{dataForm.coachTeacher}}
    </el-form-item>
    <el-form-item label="续费意向度" prop="renewalIntention">
      {{dataForm.renewalIntention}}
    </el-form-item>
    <el-form-item label="转介绍意向度" prop="introductionIntention">
      {{dataForm.introductionIntention}}
    </el-form-item>
    <el-form-item label="开课时间" prop="curriculaTime">
      {{dataForm.curriculaTime}}
    </el-form-item>
    <el-form-item label="入库时间" prop="createAt">
      {{dataForm.createAt}}
    </el-form-item>
    <el-form-item label="到期时间" prop="dueTime">
      {{dataForm.dueTime}}
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          studentId: '',
          studentName: '',
          studentStage: '',
          listeningIntentionality: '',
          sourceChannel: '',
          followStatus: '',
          followTime: '',
          classroomStatus: '',
          attendanceStatus: '',
          isUnsubscribe: '',
          auditionTime: '',
          appointmentPerson: '',
          appointmentTime: '',
          registrationIntention: '',
          studentType: '',
          studentStatus: '',
          coachTeacher: '',
          renewalIntention: '',
          introductionIntention: '',
          curriculaTime: '',
          createAt: '',
          dueTime: '',
          consultant: ''
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/generator/studentmanage/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.studentId = data.studentManage.studentId
                this.dataForm.studentName = data.studentManage.studentName
                this.dataForm.dueTime = data.studentManage.dueTime
                this.dataForm.consultant = data.studentManage.consultant
                if (data.studentManage.studentStage === 0) {
                  this.dataForm.studentStage = '意向学员'
                } else if (data.studentManage.studentStage === 1) {
                  this.dataForm.studentStage = '试听学员'
                } else if (data.studentManage.studentStage === 2) {
                  this.dataForm.studentStage = '正式学员'
                }
                this.dataForm.listeningIntentionality = this.formatIntention(data.studentManage.listeningIntentionality)
                if (data.studentManage.sourceChannel === 0) {
                  this.dataForm.sourceChannel = '无'
                } else if (data.studentManage.sourceChannel === 1) {
                  this.dataForm.sourceChannel = '公告投放'
                } else if (data.studentManage.sourceChannel === 2) {
                  this.dataForm.sourceChannel = '商场地推'
                }
                if (data.studentManage.followStatus === 0) {
                  this.dataForm.followStatus = '未跟进'
                } else if (data.studentManage.followStatus === 1) {
                  this.dataForm.followStatus = '跟进中'
                }
                this.dataForm.followTime = data.studentManage.followTime
                if (data.studentManage.classroomStatus === 0) {
                  this.dataForm.classroomStatus = '未开始'
                } else if (data.studentManage.classroomStatus === 1) {
                  this.dataForm.classroomStatus = '正在进行'
                } else if (data.studentManage.classroomStatus === 2) {
                  this.dataForm.classroomStatus = '已结束'
                } else if (data.studentManage.classroomStatus === 3) {
                  this.dataForm.classroomStatus = '已取消'
                }
                if (data.studentManage.attendanceStatus === 0) {
                  this.dataForm.attendanceStatus = '缺席'
                } else if (data.studentManage.attendanceStatus === 1) {
                  this.dataForm.attendanceStatus = '出席'
                } else if (data.studentManage.attendanceStatus === 2) {
                  this.dataForm.attendanceStatus = '迟到'
                }
                if (data.studentManage.isUnsubscribe === 0) {
                  this.dataForm.isUnsubscribe = '未退订'
                } else if (data.studentManage.isUnsubscribe === 1) {
                  this.dataForm.isUnsubscribe = '已退订'
                }
                this.dataForm.auditionTime = data.studentManage.auditionTime
                this.dataForm.appointmentPerson = data.studentManage.appointmentPerson
                this.dataForm.appointmentTime = data.studentManage.appointmentTime
                this.dataForm.registrationIntention = this.formatIntention(data.studentManage.registrationIntention)
                if (data.studentManage.studentType === 0) {
                  this.dataForm.studentType = '体验'
                } else if (data.studentManage.studentType === 1) {
                  this.dataForm.studentType = 'VIP'
                } else if (data.studentManage.studentType === 2) {
                  this.dataForm.studentType = 'SVIP'
                }
                if (data.studentManage.studentStatus === 0) {
                  this.dataForm.studentStatus = '未开课'
                } else if (data.studentManage.studentStatus === 1) {
                  this.dataForm.studentStatus = '在读'
                } else if (data.studentManage.studentStatus === 2) {
                  this.dataForm.studentStatus = '休学'
                } else if (data.studentManage.studentStatus === 3) {
                  this.dataForm.studentStatus = '毕业'
                } else if (data.studentManage.studentStatus === 3) {
                  this.dataForm.studentStatus = '退费'
                }
                this.dataForm.coachTeacher = data.studentManage.coachTeacher
                this.dataForm.renewalIntention = this.formatIntention(data.studentManage.renewalIntention)
                this.dataForm.introductionIntention = this.formatIntention(data.studentManage.introductionIntention)
                this.dataForm.curriculaTime = data.studentManage.curriculaTime
                this.dataForm.createAt = data.studentManage.createAt
              }
            })
          }
        })
      },
      // 格式化意向度
      formatIntention (item) {
        let name = null
        if (item === 0) {
          name = '未标记'
        } else if (item === 1) {
          name = '无'
        } else if (item === 2) {
          name = '低'
        } else if (item === 3) {
          name = '中'
        } else if (item === 4) {
          name = '高'
        }
        return name
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/studentmanage/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'studentId': this.dataForm.studentId,
                'studentStage': this.dataForm.studentStage,
                'listeningIntentionality': this.dataForm.listeningIntentionality,
                'sourceChannel': this.dataForm.sourceChannel,
                'followStatus': this.dataForm.followStatus,
                'followTime': this.dataForm.followTime,
                'classroomStatus': this.dataForm.classroomStatus,
                'attendanceStatus': this.dataForm.attendanceStatus,
                'isUnsubscribe': this.dataForm.isUnsubscribe,
                'auditionTime': this.dataForm.auditionTime,
                'appointmentPerson': this.dataForm.appointmentPerson,
                'appointmentTime': this.dataForm.appointmentTime,
                'registrationIntention': this.dataForm.registrationIntention,
                'studentType': this.dataForm.studentType,
                'studentStatus': this.dataForm.studentStatus,
                'coachTeacher': this.dataForm.coachTeacher,
                'renewalIntention': this.dataForm.renewalIntention,
                'introductionIntention': this.dataForm.introductionIntention,
                'curriculaTime': this.dataForm.curriculaTime,
                'delFlag': this.dataForm.delFlag,
                'creator': this.dataForm.creator,
                'createAt': this.dataForm.createAt,
                'updator': this.dataForm.updator,
                'updateAt': this.dataForm.updateAt
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
